﻿#region Imports
using System;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
#endregion Imports

namespace PlayRandom.Converters
{
    public class FavTextRedConverter : IValueConverter
    {
        #region IValueConverter Members
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var delimeter = System.Convert.ToChar(parameter); // '♥';
            var buttonText = System.Convert.ToString(value); // "abc♥def♥xyz"
            var buttonTextParts = buttonText.Split(delimeter); // "0-abc|1-def|2-xyz"

            TextBlock txtbContent = new TextBlock();
            for (int i = 0; i < buttonTextParts.Length; i++)
            {
                if (txtbContent.Inlines.Any()) txtbContent.Inlines.Add(new Run(delimeter.ToString()) { BaselineAlignment = BaselineAlignment.TextTop, Foreground = Brushes.Red, FontSize = 15, FontWeight = FontWeights.Bold });
                txtbContent.Inlines.Add(new Run(buttonTextParts.ElementAtOrDefault(i)) { BaselineAlignment = BaselineAlignment.Center });
            }

            return txtbContent;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
        #endregion IValueConverter Members
    }
}
